﻿using AutoMapper;
using MediatR;
using SmartProduction.Domain.客户管理;
using SmartProduction.ErrorCode;
using SmartProduction.Infarstructrue.Interface;
using SmartProduction.Read.API.Application.Commands.IndustryCommand;

namespace SmartProduction.Read.API.Application.CommandHandlers.IndustryHandler
{
    /// <summary>
    /// 客户行业查询命令处理
    /// </summary>
    public class IndustryCommandHandler : IRequestHandler<IndustryQueryCommand, APIResult<List<Industry>>>
    {
        /// <summary>
        /// 客户行业仓储
        /// </summary>
        private readonly IBaseRepository<Industry> industryRepository;

        /// <summary>
        /// 映射
        /// </summary>
        private readonly IMapper mapper;

        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="industryRepository">客户行业仓储</param>
        /// <param name="mapper">映射</param>
        public IndustryCommandHandler(IBaseRepository<Industry> industryRepository,IMapper mapper)
        {
            this.industryRepository = industryRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>返回</returns>
        public Task<APIResult<List<Industry>>> Handle(IndustryQueryCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<Industry>> result = new APIResult<List<Industry>>();
                result.Code = APIEnums.查询成功;
                result.Msg = APIEnums.查询成功.ToString();
                var list = industryRepository.GetAll().Result;
                result.data = list.ToList();
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
